<!DOCTYPE html>
<?php require './template/header.php'; ?>
<?php
function CovertVn($str)
{
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|�� �|ặ|ẳ|ẵ)/", 'a', $str);
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|�� �|ợ|ở|ỡ)/", 'o', $str);
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
$str = preg_replace("/(đ)/", 'd', $str);
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|�� �|Ặ|Ẳ|Ẵ)/", 'A', $str);
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|�� �|Ợ|Ở|Ỡ)/", 'O', $str);
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
$str = preg_replace("/(Đ)/", 'D', $str);
$str = preg_replace("/( )/", '_', $str);
return $str;
}

if (isset($_GET['btnName'])) {
    $kw = preg_replace('/[^A-Za-z]/', ' ', mysql_real_escape_string(strtolower( CovertVn($_GET['btnName']) )) );
    $sql=" select * from tbl_products a left join tbl_images b
                                on a.pro_id = b.pro_id
                                where a.name like '%{$kw}%'";
}

    $rows = $db->fetchAll($sql);
?>


<div id="container">
    <div id="left-panel">
        <div class="left-stuff">
            <h3>Sản phẩm bán chạy</h3>
            <div class="pro-list">
                <div class="pro-item">
                    <a href="#"><image src="products/images/p1.jpg"></a>
                    <a href="#">Bep Gas âm Faber FB-702BG</a>
                    <span class="price p-new">8.480.000 VNĐ</span>
                    <span class="price p-old">11.000.000 VNĐ</span>
                </div>
                <div class="pro-item">
                    <a href="#"><image src="products/images/p2.jpg"></a>
                    <a href="#">Bep Gas âm Faber FB-702BG</a>
                    <span class="price p-new">8.480.000 VNĐ</span>
                    <span class="price p-old">11.000.000 VNĐ</span>
                </div>
            </div>
        </div>
    </div>
    <div id="content">

        <div class="products">

            <div class="products-title">
                <h3><a href="index.php">Trang Chủ</a><span style=" color:red; font-size: 16px;"> > Tìm kiếm</span></h3>
            </div>
            <?php foreach ($rows as $key => $value) { ?>
                <div class="product">
                    <a href="product-detail.php?id=<?php echo $row['pro_id']; ?>"><img src="<?php echo $value['url']; ?>" /></a>
                    <a href="pproduct-detail.php?id=<?php echo $row['pro_id']; ?>"><h4> <?php echo $value['name']; ?> </h4></a>
                    <i>Tiết kiệm: 1.480.000 VNĐ</i>
                    <p><?php echo number_format($value['price'], 0, ',', '.') . " VNĐ"; ?></p>
                </div>
            <?php } ?>  
        </div>

    </div>
    <?php require './template/footer.php'; ?>